#include "common.h"

extern BuiltinCmd blt[MAX_BUILTIN_FUNC_NUM];

int append(int * retc, char ** retv, const int argc, const char ** argv) {
    if(retc)
        *retc = 0;

    if(argc == 0)
        return 1;

    /*int cmdIdx = findBuiltinCmd(argv[0]);
    if(cmdIdx < 0) {
        printf("command: %s, non-builtin command\n", argv[0]);
        return 0;
    }

    printf("command: %s, builtin command\n  %s\n", argv[0], blt[cmdIdx].desc);
    /** Add your man function here */
    FILE *fp;
    fp=fopen(argv[0],"a+");
    fprintf(fp,"\n");
    fprintf(fp,argv[1]);
    fputc('\n',fp);
    fclose(fp);

    return 0;
}

int appendAddBuiltin(){
    BuiltinCmd x;
    strcpy(x.name, "append");
    strcpy(x.desc, "Add the string STR to the last bit of a normal file, then insert separator (default is a space character) between multiple STR inputs, and finally add a newline character \n. When the -n setting is enabled, the newline character is not added at the end. If file is a directory, no action is taken.");
    x.hasAction = false;
    x.func = &append;

    x.optNum = 0;
    memset(x.opt, 0, sizeof(x.opt));

    addBuiltinCmd(&x);
    return 0;
}
